using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Windows.Forms;
using THSERP.BusinessEntities;
using THSERP.BaseProvider;
namespace THSERP.Modules.LayBy
{
    public partial class ARLayByItemsGridControl : THSGridControl
    {
        public override void InitGridControlDataSource()
        {
            LayByEntities entity = (LayByEntities)((BaseModuleERP)Screen.Module).CurrentModuleEntity;
            BindingSource bds = new BindingSource();
            bds.DataSource = entity.ARSaleOrderItemsList;
            this.DataSource = bds;
        }

        protected override DevExpress.XtraGrid.Views.Grid.GridView InitializeGridView()
        {
            DevExpress.XtraGrid.Views.Grid.GridView gridView = base.InitializeGridView();

            //Check edit item privilege_Hieu.nguyen_29/04/2010
            LayByEntities entity = (LayByEntities)((BaseModuleERP)Screen.Module).CurrentModuleEntity;
            if (entity.Module.HasPrivilege("EditItem"))
            {
                if (gridView.Columns["ARSaleOrderItemProductQty"] != null)
                    gridView.Columns["ARSaleOrderItemProductQty"].OptionsColumn.AllowEdit = true;
                if (gridView.Columns["ARSaleOrderItemProductUnitPrice"] != null)
                    gridView.Columns["ARSaleOrderItemProductUnitPrice"].OptionsColumn.AllowEdit = true;
            }
            return gridView;
        }

        protected override void GridView_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
        {
            base.GridView_CellValueChanged(sender, e);

            LayByEntities entity = (LayByEntities)(this.Screen.Module as BaseModuleERP).CurrentModuleEntity;
            if (entity.ARSaleOrderItemsList.CurrentIndex >= 0)
            {
                entity.ModuleObjects[SaleOrder.SaleOrderEntities.strARSaleOrderItemsObjectName] = entity.ARSaleOrderItemsList[entity.ARSaleOrderItemsList.CurrentIndex].SetToBusinessObject(SaleOrder.SaleOrderEntities.strARSaleOrderItemsObjectName);
                (entity.Module as LayByModule).ChangeItemFromSaleOrderItemsList();
            }
        }

        protected override string GetLookupTableDisplayColumn(string strLookupTableName)
        {
            switch (strLookupTableName)
            {
                case "ICProducts":
                    return "ICProductNo";
                default:
                    return base.GetLookupTableDisplayColumn(strLookupTableName);
            }
        }
    }
}
